﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SocketHelper
{
    public class AnalysisCommand
    {
        /// <summary>
        /// 执行命令
        /// </summary>
        /// <param name="command"></param>
        public static void excuteCommand(string command, string[] obj)
        {
            switch (command)
            {
                case "unzip"://服务端命令                    
                    string file = obj[0];
                    ZipUtility.UnZip(file, Path.GetDirectoryName(file), "");
                    Common.ConsoleM("解压完成");
                    break;
                default://服务端命令
                    Common.ConsoleM("来自客户端的调戏:" + command);
                    break;
            }
        }

        public static void sendCommand(string command, string[] obj)
        {
            string ip = System.Configuration.ConfigurationManager.AppSettings["RemoteIP"];
            int port = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["RemotePort"]);
            switch (command)
            {
                case "file"://客户端命令
                    if (obj.Length == 0)
                    {                       
                        Common.Command_File(ip, port);
                    }
                    else
                    {
                        ip = obj[0];
                        port = Convert.ToInt32(obj[1]);
                        string path = obj[2];
                        Common.SendFile(ip, port, path);
                    }
                    break;
                case "path":

                    break;
                case "help"://客户端命令
                    StreamReader sr = new StreamReader("help.txt", Encoding.Default);
                    String line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        Common.ConsoleM(line.ToString());
                    }
                    break;
                default:
                    Common.SendMsg(ip, port, command);
                    break;
            }
        }


    }
}
